package com.hongchen.model;

import com.jfinal.plugin.activerecord.generator.BaseModelGenerator;
import com.jfinal.plugin.activerecord.generator.TableMeta;

public class _BaseModelGenerate extends BaseModelGenerator {

	public _BaseModelGenerate(String baseModelPackageName, String baseModelOutputDir, Class<?> clazz) {
		super(baseModelPackageName, baseModelOutputDir);
		StringBuffer sb = new StringBuffer();
		sb.append("/**%n").append(" * 该类是根据数据库自动生成的，请不要修改！%n").append(" */%n");
		sb.append("@SuppressWarnings(\"serial\")%n");
		sb.append("public abstract class %s<M extends %s<M>> extends ").append(clazz.getSimpleName())
				.append("<M> implements IBean {%n%n");
		this.classDefineTemplate = sb.toString();
		importTemplate = "import " + clazz.getName() + ";%n" + "import com.jfinal.plugin.activerecord.IBean;%n%n";

	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see com.jfinal.plugin.activerecord.generator.BaseModelGenerator#
	 * genClassDefine(com.jfinal.plugin.activerecord.generator.TableMeta,
	 * java.lang.StringBuilder)
	 */
	@Override
	protected void genClassDefine(TableMeta tableMeta, StringBuilder ret) {
		String template = generateChainSetter ? classDefineForSetterChainTemplate : classDefineTemplate;
		template += "\t/**%n\t * " + tableMeta.modelName + "对应的数据库表名%n\t **/%n";
		template += "\tpublic static final String TABLE_NAME = \"" + tableMeta.name + "\";%n%n";
		ret.append(String.format(template, tableMeta.baseModelName, tableMeta.baseModelName));

	}

}
